﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Watermark_WPF
{
    public class WatermarkControl : UniformGrid
    {
        static WatermarkControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(WatermarkControl), new FrameworkPropertyMetadata(typeof(WatermarkControl)));
        }

        public static readonly DependencyProperty WatermarkTextProperty = DependencyProperty.Register("WatermarkText", typeof(string), typeof(WatermarkControl));
        public static readonly DependencyProperty WatermarkFontSizeProperty = DependencyProperty.Register("WatermarkFontSize", typeof(double), typeof(WatermarkControl));

        public WatermarkControl()
        {
            InitDefaultParams();
            InitWatermarkContent();
            InitRotate();
        }

        #region Init

        private void InitDefaultParams()
        {
            this.IsHitTestVisible = false;
            this.Margin = new Thickness(-1000);
        }

        private void InitWatermarkContent()
        {
            for (int i = 0; i < 160; i++)
            {
                Label label = new Label();
                if (i % 2 == 0)
                {
                    label.MinHeight = 80;
                    label.Content = "BigFlowerFat | 2003001\n192.168.1.1 | 2022/2/25 18:23";
                    label.Foreground = new SolidColorBrush(Color.FromArgb(100, 100, 100, 100));
                }
                this.Children.Add(label);
            }
        }

        private void InitRotate()
        {
            RotateTransform rtf = new RotateTransform(-15, 0.5, 0.5);
            this.LayoutTransform = rtf;
        }

        #endregion

        #region CustomProperty
        /// <summary>
        /// 水印内容
        /// </summary>
        public string WatermarkText
        {
            get { return (string)this.GetValue(WatermarkTextProperty); }
            set { this.SetValue(WatermarkTextProperty, value); }
        }
        /// <summary>
        /// 水印内容
        /// </summary>
        public double WatermarkFontSize
        {
            get { return (double)this.GetValue(WatermarkFontSizeProperty); }
            set { this.SetValue(WatermarkFontSizeProperty, value); }
        }
        #endregion
    }
}
